﻿/*
Copyright 2010 Shane Ng

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using javax.servlet.http;

namespace Jeans {
    public class HttpSessionAdapter : HttpSession{
        private HttpSessionState session;
        public HttpSessionAdapter(HttpSessionState session) {
            this.session = session;
        }

        public object getAttribute(string str) {
            return session[str];
        }

        public java.util.Enumeration getAttributeNames() {
            return new JavaEnumerator<string>(session.Keys.Cast<string>());
        }

        public long getCreationTime() {
            throw new NotImplementedException();
        }

        public string getId() {
            return session.SessionID;
        }

        public long getLastAccessedTime() {
            throw new NotImplementedException();
        }

        public int getMaxInactiveInterval() {
            return session.Timeout;
        }

        public javax.servlet.ServletContext getServletContext() {
            return ServletContextAdapter.Instance;
        }

        public HttpSessionContext getSessionContext() {
            throw new NotImplementedException();
        }

        public object getValue(string str) {
            throw new NotImplementedException();
        }

        public string[] getValueNames() {
            throw new NotImplementedException();
        }

        public void invalidate() {
            session.Abandon();
        }

        public bool isNew() {
            return session.IsNewSession;
        }

        public void putValue(string str, object obj) {
            throw new NotImplementedException();
        }

        public void removeAttribute(string str) {
            session.Remove(str);
        }

        public void removeValue(string str) {
            throw new NotImplementedException();
        }

        public void setAttribute(string str, object obj) {
            session[str] = obj;
        }

        public void setMaxInactiveInterval(int i) {
            session.Timeout = i;
        }
    }
}